package two.chapter_1.c1_1;

import com.sun.org.apache.regexp.internal.RE;
import edu.princeton.cs.algs4.StdOut;

public class Ex1_1_20 {

    public static void main(String[] args) {

        StdOut.println(factorialLn(12));

    }


    /**
     * 关键点：ln(N!)=lnN+ln(N-1!)
     * @param N
     * @return
     */
   private static double factorialLn(int N){
        if (N<=0){
            return Double.NaN;
        }
        if (N==1){
            return 0;
        }

        return Math.log(N)+factorialLn(N-1);
   }



}
